The Kinetis SDK provides a Software Timer (SWT) for timeout and delay.
More...
If it is an int8_t the counter will count up to 127ms, int16_t up to 32767ms and int32_t up to 2147483647ms.
This data type should be unsigned and will count up to 255ms if it is uint8_t, 65535ms for uint16_t and 4294967295ms for uint32_t.
| Enumerator |
|---|
| kSwTimerChannelExpired |
Indicates the timer channel has counted the given ms.
|
| kSwTimerChannelStillCounting |
Indicates the timeout of the channel has not expired and the timer is still counting.
|
| kSwTimerChannelIsDisable |
Indicates the timer channel is not reserved.
|
| kSwTimerChannelNotAvailable |
Indicates there are not available channels to reserve or the requested channel is not available.
|
| Enumerator |
|---|
| kSwTimerStatusSuccess |
The execution was successful.
|
| kSwTimerStatusFail |
The execution failed.
|
| kSwTimerStatusInvalidChannel |
The given channel is not valid.
Valid channels are 0 to (SW_TIMER_NUMBER_CHANNELS - 1).
|
| uint32_t sw_timer_init_service |
( |
void |
| ) |
|
Prepares variables and HAL layer to provide timer services. Starts the free running counter which will be available to get its value any time while the service is running; it is useful whenever a module wants to keep track of time, but do not wants to reserve a channel.
- Returns
- status_t Returns software timer status after initialization.
- Return values
-
| kSwTimerStatusSuccess | The initialization was successful and the software timer is ready to provide services. |
| kSwTimerStatusFail | The initialization failed. |
| void sw_timer_shutdown_service |
( |
void |
| ) |
|
Shutdown HAL layer, so no timer service can be provided after the execution of this function.
- Returns
- void
| uint8_t sw_timer_reserve_channel |
( |
void |
| ) |
|
- Returns
- uint8_t Returns the number of the channel that was reserved.
- Return values
-
| Any | value between 0 and SW_TIMER_NUMBER_CHANNELS is a valid channel. It indicates the channel was reserved and can be used. |
| kSwTimerChannelNotAvailable | If there is not any available channel, because all channels are already reserved. |
The timer has to be previously started to return a valid status.
- Parameters
-
| timerChannel | [in] Indicates the timer channel which status is going to be returned. |
- Returns
- sw_timer_channel_status_t Current status of the given timer channel.
- Return values
-
| kSwTimerChannelExpired | Indicates the timer channel has counted the given ms. |
| kSwTimerChannelStillCounting | Indicates the timeout of the channel has not expired and the timer is still counting. |
| kSwTimerChannelIsDisable | Indicates the timer channel is not reserved. |
| kSwTimerChannelNotAvailable | Indicates the timer channel is invalid. |
| uint32_t sw_timer_start_channel |
( |
uint8_t |
timerChannel, |
|
|
time_counter_t |
timeout |
|
) |
| |
The timer channel has to be previously reserved.
- Parameters
-
| timerChannel | [in] Indicates the timer channel that is going to be started. |
| timeout | [in] Time in ms that the timer channel will count. The timeout should be a multiple of count unit of the timer, otherwise it will be taken the integer part of the division and the exact count will not be achieved |
- Returns
- status_t Reports failures in the execution of the function.
- Return values
-
| kSwTimerStatusSuccess | A channel was started successfully. |
| kSwTimerStatusInvalidChannel | The timer channel is invalid, it does not exist. |
| uint32_t sw_timer_release_channel |
( |
uint8_t |
timerChannel | ) |
|
- Parameters
-
| timerChannel | [in] Identifier of the timer channel. |
- Returns
- status_t Reports failures in the execution of the function.
- Return values
-
| kSwTimerStatusSuccess | A channel was released successfully. |
| kSwTimerStatusInvalidChannel | The timer channel is invalid, it does not exist. |
Any module can keep track of the time by reading this counter and calculates time difference. No reservation of timer channel is needed. Consider for calculations that when the counter overflows it will start from 0 again.
- Returns
- time_free_counter_t Returns current count of the free running counter.
| void sw_timer_update_counters |
( |
void |
| ) |
|